﻿@using System.Security.Authentication
@using ImapX
@{
    ViewBag.Title = "Sign in";
}

<header>
    <div class="logo"></div>
</header>
<div class="content">
    @using (Html.BeginForm("signin", "auth", FormMethod.Post, new { novalidate = 1, id = "frmSignIn" }))
    {
        <div class="server">
            <input type="text" name="server" placeholder="Server" value="imap.gmail.com" />
        </div>
        <div class="port">
            <input type="number" name="port" placeholder="Port" value="@ImapBase.DefaultImapSslPort" />
        </div>
        <div class="ssl">
            <select name="ssl">
                <option value="@SslProtocols.None">No SSL</option>
                <option value="@SslProtocols.Default" selected>SSL</option>
                <option value="@SslProtocols.Tls">TLS</option>
            </select>
        </div>
        <div class="clear"></div>
        <input type="text" name="username" placeholder="Username or E-mail" />
        <input type="password" name="password" placeholder="Password" />
        <a class="submit blue remove-bottom centered">
            <span class="base"><span class="icon icon-log-in"></span> <span class="text">Sign in</span></span>
            <span class="notify notify-error"><span class="icon icon-remove-circle"></span> <span class="text"></span></span>
            <span class="notify notify-success"><span class="icon icon-ok"></span> <span class="text"></span></span>
        </a>
    }
    <div style="display:none; text-align: center;" class="wait">
        Loading...
    </div>
</div>
@section scripts {
    @Scripts.Render("~/js/forms")
    <script>
        $(function() {
            $('#frmSignIn').trForm({
                success: function(data) {
                    if (data.result == false)
                        this.notify('invalid', data.error);
                    else if (data.redirect) {
                        $('#frmSignIn').slideUp('fast', function() {
                            $('.wait').slideDown('fast');
                        });
                        
                        location.href = data.redirect;
                    }
                },
                400: function() {
                    this.notify('invalid', 'Неверные данные');
                },
                408: function() {
                    this.notify('invalid', 'Превышенно время выполнения');
                },
                error: function(a, b, statusText) {
                    this.notify('invalid', 'Серверная ошибка');
                }
            });
        });
    </script>
}